﻿#include "PyFITKMaterialsFluid.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsMaterial.h"
#include "FITKAcousticsMaterialsFluid.h"

namespace Acoustics
{
    PyFITKMaterialsFluid::PyFITKMaterialsFluid(const QString & name):
        Acoustics::PyFITKMaterialsBase(name)
    {  
    }

    bool PyFITKMaterialsFluid::setFluidProp(double soundSpeed, double density, double viscosity, double specificHeat, int type)
    {
        if (type<1 ||type>2 || !_material)return false;
        if(soundSpeed<0|| density<0|| viscosity<0|| specificHeat<0)return false;

        FITKAcousticsMaterialsFluid *fluid= dynamic_cast<Acoustics::FITKAcousticsMaterialsFluid*>(_material);
        if (!fluid)return false;

        fluid->setSpeedOfSound(soundSpeed);
        fluid->setDensity(density);
        fluid->setKinematicViscosity(viscosity);
        fluid->setSpecificHeatsRatio(specificHeat);
        fluid->setMolecularMass(0);//摩尔质量默认为0
        fluid->setType((FITKAcousticsMaterialsFluid::FluidType)type);
        fluid->setPrandtlNumber((type==1) ? 0.7:7);
        return true;
    }

    bool PyFITKMaterialsFluid::createMaterial(const QString & name)
    {
        if(name=="")return false;
        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
        if (matMgr == nullptr) return false;
        if (matMgr->getDataByName(name))return false;

        FITKAcousticsMaterialsFluid * fluid= new FITKAcousticsMaterialsFluid();
        fluid->setDataObjectName(name);
        _material = fluid;
        matMgr->appendDataObj(_material);

        return true;
    }
}